<template>
  <div>
    <header class="home-header"  :class="{'active' : headerActive}" >
      <router-link tag="i" to="./category" class="iconfont icon-fenlei"></router-link>
      <div class="header-search">
        <span class="app-name">S</span>
        <i class="iconfont icon-search"></i>
        <router-link tag="span" class="search-title" to="./search">蓝天电视</router-link>
      </div>
<!--      <router-link tag="span" to="./login">登录</router-link>-->
<!--      判断是否登录-->
      <router-link tag="span" to="./login" v-if="!isLogin">登录</router-link>
      <router-link tag="span" to="./user" v-else>
        <i class="iconfont icon-people"></i>
      </router-link>

    </header>
<!--    <header class="home-header" >-->
<!--      <router-link tag="i" to="./category" class="iconfont icon-fenlei"></router-link>-->
<!--      <div class="header-search">-->
<!--        <span class="app-name">S</span>-->
<!--        <i class="iconfont icon-search"></i>-->
<!--        <router-link tag="span" class="search-title" to="./search">蓝天电视</router-link>-->
<!--      </div>-->
<!--      <router-link tag="span" to="./login">登录</router-link>-->
<!--    </header>-->
    <div class="swiper-container">
      <div class="swiper-wrapper">
        <div class="swiper-slide"><img src="./imgs/rowing/s1.png" alt="" width="100%" height="100%"></div>
        <div class="swiper-slide"><img src="./imgs/rowing/s2.png" alt="" width="100%"></div>
        <div class="swiper-slide"><img src="./imgs/rowing/s3.png" alt="" width="100%"></div>
        <div class="swiper-slide"><img src="./imgs/rowing/s4.png" alt="" width="100%"></div>
      </div>
      <!-- 如果需要分页器 -->
      <div class="swiper-pagination"></div>
    </div>
    <div class="home-nav">
      <div class="home-nav-content">
        <div class="nav-content-item">
          <img src="./imgs/nav/nav_icon01.png" alt="">
          <span>超市</span>
        </div>
        <div class="nav-content-item">
          <img src="./imgs/nav/nav_icon02.png" alt="">
          <span>全球购</span>
        </div>
        <div class="nav-content-item">
          <img src="./imgs/nav/nav_icon03.png" alt="">
          <span>服装</span>
        </div>
        <div class="nav-content-item">
          <img src="./imgs/nav/nav_icon04.png" alt="">
          <span>生鲜</span>
        </div>
        <div class="nav-content-item">
          <img src="./imgs/nav/nav_icon05.png" alt="">
          <span>到家</span>
        </div>
      </div>
      <div class="home-nav-content">
        <div class="nav-content-item">
          <img src="./imgs/nav/nav_icon06.png" alt="">
          <span>充值</span>
        </div>
        <div class="nav-content-item">
          <img src="./imgs/nav/nav_icon07.png" alt="">
          <span>拼购</span>
        </div>
        <div class="nav-content-item">
          <img src="./imgs/nav/nav_icon08.png" alt="">
          <span>领劵</span>
        </div>
        <div class="nav-content-item">
          <img src="./imgs/nav/nav_icon09.png" alt="">
          <span>分佣</span>
        </div>
        <div class="nav-content-item">
          <img src="./imgs/nav/nav_icon10.png" alt="">
          <span>全部</span>
        </div>
      </div>
    </div>
    <div class="floor-list">
      <div class="floor-wrap">
        <img src="./imgs/floor_head/f1.png" alt="" class="floor-head">
        <div class="floor-content">
          <div class="floor-category">
            <p>经典手表</p>
            <p>为爱倾注时间</p>
            <div class="floor-products">
              <img src="./imgs/floor_pros/p1.png" alt="">
              <img src="./imgs/floor_pros/p2.png" alt="">
            </div>
          </div>
          <div class="floor-category">
            <p>智能家电</p>
            <p>家电狂欢 精彩有你</p>
            <div class="floor-products">
              <img src="./imgs/floor_pros/p3.png" alt="">
              <img src="./imgs/floor_pros/p4.png" alt="">
            </div>
          </div>
        </div>
        <div class="floor-content">
          <div class="floor-category">
            <p>超市</p>
            <p>超市大放价 抢超值好货</p>
            <div class="floor-products">
              <img src="./imgs/floor_pros/p5.png" alt="">
              <img src="./imgs/floor_pros/p6.png" alt="">
            </div>
          </div>
          <div class="floor-category">
            <p>爱家</p>
            <p>家纺热卖</p>
            <div class="floor-products">
              <img src="./imgs/floor_pros/p7.png" alt="">
              <img src="./imgs/floor_pros/p8.png" alt="">
            </div>
          </div>

          <div class="floor-category">
            <p>爱家</p>
            <p>家纺热卖</p>
            <div class="floor-products">
              <img src="./imgs/floor_pros/p7.png" alt="">
              <img src="./imgs/floor_pros/p8.png" alt="">
            </div>
          </div>

        </div>
      </div>
    </div>
    <navBar></navBar>
  </div>
</template>

<script>
  import navBar from './../../components/navBar'
  import Swiper from 'swiper'
  import 'swiper/dist/css/swiper.min.css'
  // 登录
  import {homeData,checkLogin} from "../../service/getData";

  export default {
    name: "home",
    data(){
      return{
        headerActive: false,
        isLogin:false,
      }
    },
    methods: {
      pageScroll() {
        let scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop
        scrollTop > 100 ? this.headerActive = true : this.headerActive = false
      }
    },

    components:{
      navBar
    },
    // 登陆判断
    beforeCreate(){
      checkLogin().then((res)=>{
        res.status==1? this.isLogin = false:this.isLogin=true
      })
    },

    // 轮播
    mounted() {
      // 2. 创建swiper实例
      new Swiper ('.swiper-container', {
        autoplay:true,   //自动轮播
        loop: true,
        // 如果需要分页器
        pagination: {
          el: '.swiper-pagination',
        }
      })
      window.addEventListener('scroll', this.pageScroll)
    }

  }
</script>

<style scoped lang="scss">
  @import "../../common/style/mixin";
  /***************顶部搜索栏**************/
  .home-header{
    position: fixed;
    left: 0;
    top: 0;
    @include fj;
    width: 100%;
    height: 100px;
    line-height: 100px;
    padding: 0 30px;
    @include boxSizing;
    font-size: 30px;
    color: #ffffff;
    z-index: 1000;
    background-color: pink;
    &.active{
      background: red;
    }
    .icon-fenlei{
      font-size: 50px;
    }
    .header-search{
      display: flex;
      width: 74%;
      height: 40px;
      line-height: 40px;
      margin: 20px 0;
      padding: 10px 0;
      color: #232326;
      background: #fff;
      @include  borderRadius(40px);
      .app-name{
        padding: 0 20px;
        color: red;
        font-size: 40px;
        font-weight: bold;
        border-right: 1px solid #666;
      }
      .icon-search{
        padding: 0 20px;
      }
      .search-title{
        font-size: 24px;
        color: #666;
      }

    }
    .icon-people{

    }
  }
  .home-nav-content{
    background-color: #fff;
    display: flex;
    flex-shrink: 0;
    flex-wrap: wrap;
    width: 100%;
    padding-bottom: 26px;
    .nav-content-item{
      display: flex;
      flex-direction: column;
      width: 20%;
      text-align: center;
      img {
        width: 80px;
        height: 80px;
        margin: 26px auto 16px auto;
      }
    }
  }
  .floor-list {
    width: 100%;
    padding-bottom: 100px;
    .floor-head {
      width: 100%;
      height: 80px;
      background: #F6F6F6;
    }
    .floor-content {
      display: flex;
      flex-shrink: 0;
      flex-wrap: wrap;
      width: 100%;
      @include boxSizing;
      .floor-category {
        width: 50%;
        padding: 20px;
        border-right: 1px solid #dcdcdc;
        border-bottom: 1px solid #dcdcdc;
        @include boxSizing;
        background-color: #fff;
        &:nth-child(2n) {
          border-right: none;
        }
        p {
          font-size: 34px;
          color: #333;
          &:nth-child(2) {
            padding: 10px 0;
            font-size: 26px;
            color: $red;
          }
        }
        .floor-products {
          display: flex;
          justify-content: space-around;
          width: 100%;
          img {
            width: 130px;
            height: 130px;
          }
        }
      }
    }
  }
</style>
